package com.hit.aircraftwar.application;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.hit.aircraftwar.R;
import com.hit.aircraftwar.activity.MainActivity;
import com.hit.aircraftwar.aircraft.*;
import com.hit.aircraftwar.bullet.*;
import com.hit.aircraftwar.supply.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 综合管理图片的加载，访问
 * 提供图片的静态访问方法
 *
 * @author hitsz
 */
public class ImageManager {

    /**
     * 类名-图片 映射，存储各基类的图片 <br>
     * 可使用 CLASSNAME_IMAGE_MAP.get( obj.getClass().getName() ) 获得 obj 所属基类对应的图片
     */
    private static final Map<String, Integer> CLASSNAME_IMAGE_MAP = new HashMap<>();

    public static int BACKGROUND_IMAGE0 = R.drawable.bg;
    public static int BACKGROUND_IMAGE1 = R.drawable.bg4;
    public static int BACKGROUND_IMAGE2 = R.drawable.bg5;

    public static int HERO_IMAGE = R.drawable.hero;
    public static int HERO2_IMAGE = R.drawable.hero2;
    public static int HERO_BULLET_IMAGE = R.drawable.bullet_hero;
    public static int ENEMY_BULLET_IMAGE = R.drawable.bullet_enemy;
    public static int TRACK_BULLET_IMAGE = R.drawable.bullet_track;
    public static int MOB_ENEMY_IMAGE = R.drawable.mob;
    public static int ELITE_ENEMY_IMAGE  = R.drawable.elite;
    public static int BOSS_IMAGE  = R.drawable.boss;

    public static int HP_SUPPLY_IMAGE = R.drawable.prop_blood;
    public static int BOMB_SUPPLY_IMAGE = R.drawable.prop_bomb;
    public static int FIRE_SUPPLY_IMAGE = R.drawable.prop_bullet;

    public static int BOOM_IMAGE = R.drawable.boom;
    public static int BULLET_BOOM_IMAGE = R.drawable.bullet_boom;
    public static int AIRCRAFT_BOOM_IMAGE = R.drawable.aircraft_boom;

    public static int MISSILE_IMAGE = R.drawable.missile;
    public static int MISSILE2_IMAGE = R.drawable.missile2;
    public static int MISSILE_BOOM_IMAGE = R.drawable.missileboom;

    static {
        CLASSNAME_IMAGE_MAP.put(HeroAircraft.class.getName(), HERO_IMAGE);
        CLASSNAME_IMAGE_MAP.put(MobEnemy.class.getName(), MOB_ENEMY_IMAGE);
        CLASSNAME_IMAGE_MAP.put(EliteEnemy.class.getName(), ELITE_ENEMY_IMAGE);
        CLASSNAME_IMAGE_MAP.put(HeroBullet.class.getName(), HERO_BULLET_IMAGE);
        CLASSNAME_IMAGE_MAP.put(EnemyBullet.class.getName(), ENEMY_BULLET_IMAGE);
        CLASSNAME_IMAGE_MAP.put(TrackBullet.class.getName(), TRACK_BULLET_IMAGE);
        CLASSNAME_IMAGE_MAP.put(HpSupply.class.getName(), HP_SUPPLY_IMAGE);
        CLASSNAME_IMAGE_MAP.put(BombSupply.class.getName(), BOMB_SUPPLY_IMAGE);
        CLASSNAME_IMAGE_MAP.put(FireSupply.class.getName(), FIRE_SUPPLY_IMAGE);
        CLASSNAME_IMAGE_MAP.put(Boss.class.getName(), BOSS_IMAGE);
        CLASSNAME_IMAGE_MAP.put(Missile.class.getName(), MISSILE_IMAGE);
        CLASSNAME_IMAGE_MAP.put(MissileBoom.class.getName(), MISSILE_BOOM_IMAGE);
    }

    public static Bitmap HERO_BITMAP = getBitmap(HERO_IMAGE);
    public static Bitmap HERO2_BITMAP = getBitmap(HERO2_IMAGE);
    public static Bitmap MOB_ENEMY_BITMAP = getBitmap(MOB_ENEMY_IMAGE);
    public static Bitmap ELITE_ENEMY_BITMAP = getBitmap(ELITE_ENEMY_IMAGE);
    public static Bitmap BOSS_BITMAP = getBitmap(BOSS_IMAGE);

    public static Bitmap HERO_BULLET_BITMAP = getBitmap(HERO_BULLET_IMAGE);
    public static Bitmap ENEMY_BULLET_BITMAP = getBitmap(ENEMY_BULLET_IMAGE);

    public static Bitmap HP_SUPPLY_BITMAP = getBitmap(HP_SUPPLY_IMAGE);
    public static Bitmap BOMB_SUPPLY_BITMAP = getBitmap(BOMB_SUPPLY_IMAGE);
    public static Bitmap FIRE_SUPPLY_BITMAP = getBitmap(FIRE_SUPPLY_IMAGE);

    public static Bitmap BOOM_BITMAP = getBitmap(BOOM_IMAGE);
    public static Bitmap BULLET_BOOM_BITMAP = getBitmap(BULLET_BOOM_IMAGE);
    public static Bitmap AIRCRAFT_BOOM_BITMAP = getBitmap(AIRCRAFT_BOOM_IMAGE);
    public static Bitmap BACKGROUND_EASY_BITMAP = getBitmap(BACKGROUND_IMAGE0);
    public static Bitmap BACKGROUND_MEDIUM_BITMAP = getBitmap(BACKGROUND_IMAGE1);
    public static Bitmap BACKGROUND_HARD_BITMAP = getBitmap(BACKGROUND_IMAGE2);

    public static Bitmap MISSILE_BITMAP = getBitmap(MISSILE_IMAGE);
    public static Bitmap MISSILE_BOOM_BITMAP = getBitmap(MISSILE_BOOM_IMAGE);
    public static Bitmap MISSILE2_BITMAP = getBitmap(MISSILE2_IMAGE);

    public static Bitmap getBitmap(int image) {
        return BitmapFactory.decodeResource(MainActivity.mainActivity.getResources(), image);
    }

    public static int get(String className) {
        return CLASSNAME_IMAGE_MAP.get(className);
    }
    public static int get(Object obj) {
        if (obj == null) {
            return -1;
        }
        return get(obj.getClass().getName());
    }
    public static int getWidth(int image){
        Bitmap bitmap = getBitmap(image);
        //获取图片的宽
        return bitmap.getWidth();
    }

    public static int getHeight(int image){
        Bitmap bitmap = getBitmap(image);
        //获取图片的高
        return bitmap.getHeight();
    }
}
